package Models;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class SalesOrder {
	private int orderId;
	private Date orderDate;
	private boolean paid;
	private Customer customerId;
	private String checkNumber;
	private String checkNotes;
	private boolean exported; 
    private List<Sale> sales;
    private List<InvSalesLines> invSalesLines;
    
	public int getOrderId() {
		return orderId;
	}
	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}
	public Date getOrderDate() {
		return orderDate;
	}
	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	public boolean isPaid() {
		return paid;
	}
	public void setPaid(boolean paid) {
		this.paid = paid;
	}
	public Customer getCustomerId() {
		return customerId;
	}
	public void setCustomerId(Customer customerId) {
		this.customerId = customerId;
	}
	public String getCheckNumber() {
		return checkNumber;
	}
	public void setCheckNumber(String checkNumber) {
		this.checkNumber = checkNumber;
	}
	public String getCheckNotes() {
		return checkNotes;
	}
	public void setCheckNotes(String checkNotes) {
		this.checkNotes = checkNotes;
	}
	public boolean isExported() {
		return exported;
	}
	public void setExported(boolean exported) {
		this.exported = exported;
	}
	public List<Sale> getSales() {
		return sales;
	}
	public void setSales(List<Sale> sales) {
		this.sales = sales;
	}
	public List<InvSalesLines> getInvSalesLines() {
		return invSalesLines;
	}
	public void setInvSalesLines(List<InvSalesLines> invSalesLines) {
		this.invSalesLines = invSalesLines;
	}

	public Date getDueDate(final int term) {
		final Calendar cal = Calendar.getInstance();
		cal.setTime(orderDate);
		cal.add(Calendar.DATE, term);
		return new Date(cal.getTime().getTime());
	}

	/**
	 * Returns true if not paid and is past term time
	 * 
	 * @param term
	 *            in days
	 * @return
	 */
	public boolean isOverDue(final int term) {
		final Date now = new Date(new java.util.Date().getTime());
		return (!paid && now.after(getDueDate(term)));
	}

	public String getDisplayID() {
		final String mask = "i000000";
		final String ds = Integer.toString(orderId);
		return mask.substring(0, mask.length() - ds.length()) + ds;
	}
}
